import React, { Component } from 'react'

export default class App extends Component {
  //在构造函数里绑定this
  // constructor(props){
  //   super(props)
  //   this.handleClick = this.handleClick.bind(this)
  // }
  state = {
    msg: '🐂'
  }
  // handleClick() {
  //   console.log(this)
  //   this.setState({
  //     msg: '🐏'
  //   })
  // }

  //箭头函数
  handleClick = ()=> {
    console.log(this)
    this.setState({
      msg: '🐏'
    })
  }

  render() {
    return (
      <div>
        {/* 每次点击都触发bind */}
        {/* <button onClick={this.handleClick.bind(this)}>this修正</button> */}
        <button onClick={this.handleClick}>this修正</button>
        <h1>{this.state.msg}</h1>
      </div>
    )
  }
}
